




package formServlets;
import java.io.IOException;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.DatastoreAttributes;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.FetchOptions;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.datastore.PreparedQuery;
import com.google.appengine.api.datastore.Query;
import javax.servlet.http.HttpServlet;

//import guestbook.PMF;

public class  FetchAllCountriesServlet  extends HttpServlet  {

	
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		getServletContext().getRequestDispatcher("SNSP.html").forward(req, resp);
	}
 
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		
		DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
		// check whether data already exist for some userid else it would be over written
		DatastoreAttributes ds=datastore.getDatastoreAttributes();
		DatastoreAttributes.DatastoreType dst= ds.getDatastoreType();
		System.out.print(dst.name());
		
		Query q1 = new Query("PlaceInfo");
		
		PreparedQuery pq1 = datastore.prepare(q1);
        String countrylist=new String();
		for (Entity result : pq1.asIterable()) {
			System.out.println(result.getKind());
		  String Country = (String) result.getProperty("Country");
		  countrylist=countrylist+","+Country;
		  System.out.println(Country);
		}
		
		response.getWriter().print(countrylist);
 
	}
 
}

